home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / datasheets and manuals / Hardware / WHT / scsi / dsr_sources_2_2001 / openou < prev    next >
Text File  |  2006-10-19  |  12KB  |  518 lines

  1. **
  2. *
  3. *  OPEN OUTPUT
  4. *
  5. *  Here is where we open a file for output.  If the
  6. *  file aready exists, make sure it's not protected
  7. *  and has all the same attributes of the file we
  8. *  want to open.  I no longer deallocate the AU's.
  9. *
  10. *  If the file does not exist, see if the directory
  11. *  exists.  If it does, then create a new entry in
  12. *  the file index
  13. *
  14. **
  15.  
  16. OPENOU
  17.        BL   @GETFDR           See if the file already exists
  18.        CI   R5,0
  19.        JNE  OOU1
  20.        B    @OOU20
  21.  
  22. * The file exists
  23. *
  24. OOU1
  25.        LDCR @ZERO,4           Select RAM bank 0
  26.        MOV  @12(R5),R1        Get file flags
  27.        COC  @PROBIT,R1
  28.        JNE  OOU2
  29.        BL   @DSRERR           File protected - error
  30.        DATA >0100
  31.  
  32. OOU2
  33.        ANDI R1,>0100          Check for Data/Program
  34.        JEQ  OOU3
  35. OOUBAD BL   @DSRERR
  36.        DATA >0200             Bad open attribute
  37.  
  38. OOU3   MOV  @12(R5),R1        Check Fixed/variable
  39.        ANDI R1,>8000
  40.        MOVB @PABBUF+1,R2
  41.        ANDI R2,>1000
  42.        SLA  R2,3
  43.        C    R1,R2
  44.        JNE  OOUBAD
  45.  
  46.        MOVB @12(R5),R1        Check Display/Internal
  47.        ANDI R1,>0200
  48.        MOVB @PABBUF+1,R2
  49.        ANDI R2,>0800
  50.        SRL  R2,2
  51.        C    R1,R2
  52.        JNE  OOUBAD
  53.  
  54. * Now compare record length.  If no record length was
  55. * specified, we can continue.
  56. *
  57.        MOVB @PABBUF+4,R2
  58.        JEQ  OOU4
  59.        CB   R2,@17(R5)
  60.        JNE  OOUBAD
  61. OOU4
  62.  
  63. * Set up the file cache entry
  64.  
  65.        BL   @OSCASH
  66.  
  67. * Reset a few fields in the FDR
  68. *
  69.        LDCR @ZERO,4
  70. *      CLR  @14(R5)           Number of sectors currently allocated
  71.        MOVB @ZERO,@16(R5)     End of file offset
  72.        CLR  @18(R5)           Number of level 3 records allocated
  73.  
  74. * Write the FDR back out to disk
  75. *
  76.        LDCR @B04,4            Select RAM bank 4
  77.        MOV  @SAVEAU,R7
  78.  
  79.        BL   @ALOT
  80.  
  81.        SRL  R8,1
  82.        SRL  R7,1
  83.        JNC  OOU7
  84.        AI   R8,1
  85. OOU7
  86.        BLWP @BANKIT
  87.        DATA SCSIWT
  88.        JEQ  OOU8
  89.        BL   @DSRERR
  90.        DATA >0600             Device error
  91. OOU8
  92.  
  93. * Copy the FDR to FDR buffer in Bank 5
  94. *
  95.        LDCR @B02,4
  96.        MOV  @4(R4),R1
  97.        LI   R4,256
  98. OOU9   LDCR @ZERO,4
  99.        MOV  *R5+,R2
  100.        LDCR @B05,4
  101.        MOV  R2,*R1+
  102.        DECT R4
  103.        JNE  OOU9
  104.  
  105.        LDCR @ZERO,4
  106.        B    @DSRRT            File is open!!!
  107.  
  108. **
  109. *  The specified file does not exist.  We will have to make
  110. *  a new entry for the file in the file index of the directory
  111. *
  112. **
  113.  
  114. OOU20
  115.        BL   @GETDDR      Get the parent directory
  116.        CI   R5,0
  117.        JNE  OOU21
  118.        BL   @DSRERR      Directory does not exist
  119.        DATA >0700        File error
  120.  
  121. OOU21  LDCR @B03,4            Select RAM bank 3
  122.        CB   @22(R5),@B127     See if directory is full
  123.        JNE  OOU22
  124.        BL   @DSRERR
  125.        DATA >0400             Out of space error
  126.  
  127. OOU22  AB   @B01,@22(R5)      Increment file counter
  128.  
  129. * We will now read the DDR and write it back out with the
  130. * number of files incremented by 1.  In a perfect world,
  131. * we would try to allocate an AU for the file first.
  132. *
  133.        LDCR @B04,4            Select RAM bank 4
  134.        MOV  @SAVEAU,R7        Get AU of the DDR
  135.  
  136.        BL   @ALOT
  137.  
  138.        LI   R2,SECBUF
  139.        SRL  R8,1
  140.        JNC  OOU23
  141.        AI   R2,>100
  142. OOU23  SRL  R7,1
  143.        JNC  OOU24
  144.        AI   R8,>8000
  145. OOU24
  146.        BLWP @BANKIT
  147.        DATA SCSIRD
  148.        JEQ  OOU26
  149.  
  150. OOU25  BL   @DSRERR
  151.        DATA >0600             Device error
  152.  
  153. OOU26  AB   @B01,@22(R2)      Increment file counter
  154.        BLWP @BANKIT
  155.        DATA SCSIWT
  156.        JNE  OOU25
  157.  
  158. * Now we have to place an AU for the FDR in the file index.
  159. * We will do a cut-and-paste from the SAVE procedure.  This
  160. * really should be a subprogram since it it duplicated.
  161. *
  162.  
  163.        MOV  R5,R0            Save pointer to DDR in memory
  164.  
  165. * I am hardcoding a value of 256 for AU boundry.  I should
  166. * really get this value from the VIB
  167.  
  168.        LI   R3,-256
  169.        CLR  R7
  170.        LI   R8,1             We want 1 AU
  171.        LDCR @ZERO,4          Select RAM bank 0
  172.        BLWP @ALLOC
  173.        JNE  OOU25            Device error
  174.  
  175.        CI   R4,0             See if we got no AU's
  176.        JNE  OOU27
  177.        BL   @DSRERR
  178.        DATA >0400            Out of space
  179.  
  180. OOU27  LDCR @B02,4           Save AU we got allocated
  181.        MOV  R5,@SFDRAU
  182.  
  183. * We now have to do a binary search on all the
  184. * file names in the directory to see where it will go.
  185. *
  186.        LDCR @B02,4
  187.        LI   R2,NCB+39
  188. OOU28  CB   *R2,@PERIOD
  189.        JEQ  OOU29
  190.        DEC  R2
  191.        CI   R2,NCB-1
  192.        JNE  OOU28
  193.  
  194. OOU29  INC  R2
  195.        CI   R2,NCB+40        Make sure we don't have a 0 length
  196.        JNE  OOU31            file name
  197. OOU30  BL   @DSRERR
  198.        DATA >0700            File Error
  199. OOU31  CB   *R2,@SPACE
  200.        JEQ  OOU30
  201.  
  202. * Now copy the filename to FNCB
  203. *
  204.        LI   R1,FNCB
  205. OOU32  MOVB *R2+,R3
  206.        LDCR @ZERO,4
  207.        MOVB R3,*R1+
  208.  
  209.        LDCR @B02,4
  210.        CI   R2,NCB+40
  211.        JEQ  OOU33
  212.        CB   *R2,@SPACE
  213.        JNE  OOU32
  214.  
  215. OOU33  LDCR @ZERO,4          Select RAM bank 0
  216. OOU34  CI   R1,FNCB+10
  217.        JEQ  OOU35
  218.        MOVB @SPACE,*R1+
  219.        JMP  OOU34
  220. OOU35
  221.  
  222. * Now get the file index back so we can insert the AU
  223. * of the new FDR
  224. *
  225.  
  226.        LDCR @B03,4           Select RAM bank 3
  227.        MOV  R0,R3
  228.        MOV  @24(R3),R7       Get AU of file index
  229.  
  230.        BL   @ALOT
  231.  
  232.        LI   R4,SECBUF
  233.        SRL  R8,1
  234.        JNC  OOU36
  235.        AI   R4,>100
  236. OOU36  SRL  R7,1
  237.        JNC  OOU37
  238.        AI   R8,>8000
  239. OOU37
  240.        BLWP @BANKIT          Read the index from disk
  241.        DATA SCSIRD
  242.        JEQ  OOU38
  243.        BL   @DSRERR          Signal error
  244.        DATA >0600            Device error
  245.  
  246. OOU38  LI   R2,DFDR
  247.        LI   R3,256
  248. OOU39  MOV  *R4+,R5          Copy the index to a buffer
  249.        LDCR @B02,4
  250.        MOV  R5,*R2+
  251.        LDCR @ZERO,4
  252.        DECT R3
  253.        JNE  OOU39
  254.  
  255. * Now we have to search the index and see where our
  256. * new file will fit in alphabetically
  257. *
  258.  
  259.        LDCR @B03,4            Select RAM bank 3
  260.        MOV  R0,R3
  261.  
  262.        MOVB @22(R3),R1        Get # of files in directory
  263.        CLR  R0
  264.        SRL  R1,8
  265.        DEC  R1                Ignore our own file
  266.        JEQ  OOU48
  267.        DEC  R1
  268.  
  269. OOU40  LDCR @B02,4           Select RAM bank 2
  270.        MOV  R0,R2            Compute the midpoint
  271.        A    R1,R2
  272.        ANDI R2,>FFFE
  273.        MOV  @DFDR(R2),R7     Get AU of FDR
  274.        LI   R4,SECBUF
  275.  
  276.        BL   @ALOT
  277.  
  278.        SRL  R8,1
  279.        JNC  OOU41
  280.        AI   R4,>100
  281. OOU41  SRL  R7,1
  282.        JNC  OOU42
  283.        AI   R8,>8000
  284. OOU42
  285.  
  286. * Read the FDR from disk and compare file names
  287. *
  288.        BLWP @BANKIT
  289.        DATA SCSIRD
  290.        JEQ  OOU43
  291.        BL   @DSRERR
  292.        DATA >0600            Device Error
  293. OOU43
  294.        LI   R2,FNCB
  295. OOU44  CB   *R4+,*R2+
  296.        JL   OOU45
  297.        JH   OOU46
  298.        JMP  OOU44
  299.  
  300. OOU45  C    R0,R1
  301.        JEQ  OOU47
  302.        MOV  R0,R2
  303.        A    R1,R2
  304.        SRL  R2,1
  305.        MOV  R2,R0
  306.        INC  R0
  307.        JMP  OOU40
  308.  
  309. OOU46  C    R0,R1
  310.        JEQ  OOU48
  311.        MOV  R0,R2
  312.        A    R1,R2
  313.        SRL  R2,1
  314.        C    R2,R0
  315.        JEQ  OOU48
  316.        MOV  R2,R1
  317. *      JEQ  OOU48
  318.        DEC  R1
  319.        JMP  OOU40
  320.  
  321. OOU47  INC  R0
  322. OOU48  SLA  R0,1
  323.        AI   R0,DFDR
  324.  
  325. * Insert the AU of our new FDR into the file index.
  326. *
  327.        LDCR @B02,4           Select RAM bank 2
  328.        LI   R1,DFDR+252
  329. OOU49  C    R1,R0
  330.        JEQ  OOU50
  331.        MOV  @-2(R1),*R1
  332.        DECT R1
  333.        JMP  OOU49
  334.  
  335. OOU50  MOV  @SFDRAU,*R0      Put in AU of our new FDR in index
  336.  
  337. * Now write the new file index back out to disk
  338. *
  339.  
  340.        BL   @GETDDR          Get pointer to DDR back
  341.  
  342.        LDCR @B03,4           Select RAM bank 3
  343.        LI   R2,SECBUF
  344.        MOV  @24(R5),R7       Get AU of the file index
  345.  
  346.        BL   @ALOT
  347.  
  348.        SRL  R8,1
  349.        JNC  OOU51
  350.        AI   R2,>100
  351. OOU51  SRL  R7,1
  352.        JNC  OOU52
  353.        AI   R8,>8000
  354. OOU52
  355.        BLWP @BANKIT
  356.        DATA SCSIRD
  357.        JEQ  OOU53
  358.        BL   @DSRERR
  359.        DATA >0600            Device Error
  360.  
  361. * Now replace the file index in the SCSI buffer
  362. *
  363. OOU53  LI   R3,DFDR
  364.        LI   R1,256
  365. OOU54  LDCR @B02,4           Select RAM bank 2
  366.        MOV  *R3+,R4
  367.        LDCR @ZERO,4          Select RAM bank 0
  368.        MOV  R4,*R2+
  369.        DECT R1
  370.        JNE  OOU54
  371.  
  372.        BLWP @BANKIT          Now write back out to disk
  373.        DATA SCSIWT
  374.        JEQ  OOU55
  375.        BL   @DSRERR
  376.        DATA >0600            Device Error
  377. OOU55
  378.  
  379. * Now we are going to write out a blank FDR to the disk.
  380. * When we are done writing the contents of the file, we
  381. * will re-write the FDR.  I do it this way in case the
  382. * computer crashes when writing the data.  We will not
  383. * have a corrupt FDR.
  384. *
  385.  
  386. * Allocate an entry in the open file cache and build the FDR
  387. * in bank 5.
  388.  
  389.        BL   @OSCASH
  390.        MOV  @SFDRAU,@48(R4)  Store the FDR's AU
  391.  
  392. * Copy the file name into the FDR
  393.  
  394.        MOV  @4(R4),R1        Get FDR address
  395.        MOVB @2(R4),R10       Get FDR bank
  396.        LI   R2,FNCB
  397.        LI   R3,10
  398. OOU59  LDCR @ZERO,4
  399.        MOV  *R2+,R0
  400.        LDCR R10,4            Select the bank the FDR resides in
  401.        MOV  R0,*R1+
  402.        DECT R3
  403.        JNE  OOU59
  404.  
  405. OOU61  CLR  *R1+             Extended record length
  406.  
  407. * Here we set the file flags.  We only need to set the
  408. * variable/fixed bit and internal/display bit.
  409.  
  410.        CLR  R2
  411.        LDCR @ZERO,4          Select RAM bank 0
  412.        MOVB @PABBUF+1,R0
  413.        ANDI R0,>1000
  414.        JEQ  OOU61A
  415.        ORI  R2,>8000         Variable length records
  416. OOU61A MOVB @PABBUF+1,R0
  417.        ANDI R0,>0800
  418.        JEQ  OOU61B
  419.        ORI  R2,>0200         Internal
  420. OOU61B LDCR R10,4
  421.        MOVB R2,*R1+          File flags
  422.  
  423. * Compute the number of records per sector by dividing
  424. * the sector size (256) by record size.
  425.  
  426.        LDCR @ZERO,4
  427.        MOVB @PABBUF+4,R0     Get record size
  428.        JNE  OOU61D
  429.        LI   R0,80*256        Default record size is 80
  430. OOU61D
  431.        SRL  R0,8
  432.        CLR  R7
  433.        LI   R8,256
  434.        DIV  R0,R7
  435.        LDCR R10,4
  436.        SLA  R7,8
  437.        MOVB R7,*R1+          # of records per sector
  438.        CLR  *R1+             # of sectors allocated
  439.        MOVB @ZERO,*R1+       End of file offset
  440.        LDCR @ZERO,4          Get record length
  441.        MOVB @PABBUF+4,R0
  442.        JNE  OOU61C           If 0, use the default of 80
  443.        MOV  @PABADR,R0       Store record length in
  444.        AI   R0,4               caller's PAB
  445.        ORI  R0,>4000
  446.        SWPB R0
  447.        MOVB R0,@VDPWA
  448.        SWPB R0
  449.        MOVB R0,@VDPWA
  450.        MOVB @B80,R0
  451.        MOVB R0,@VDPWD
  452. OOU61C
  453.        LDCR R10,4
  454.        MOVB R0,*R1+
  455.        CLR  *R1+             Level 3 records allocated
  456.        CLR  *R1+             Date & Time of creation
  457.        CLR  *R1+                     "
  458.        CLR  *R1+             Date & Time of update
  459.        CLR  *R1+                     "
  460.        LI   R0,'FI'
  461.        MOV  R0,*R1+
  462.        CLR  *R1+             Pointer to parent AU
  463.        CLR  *R1+             Pointer to offspring AU
  464.        CLR  *R1+             # of AUs for this FDR
  465.        LDCR @B03,4
  466.        MOV  @24(R5),R0       Get pointer to FDIR
  467.        LDCR R10,4
  468.        MOV  R0,*R1+          Pointer to FDIR
  469.        CLR  *R1+             Extended info
  470. OOU62  CLR  *R1+             Clear the data chain
  471.        MOV  R1,R0
  472.        ANDI R0,>00FF         This is ugly, but I'm in a hurry
  473.        JNE  OOU62
  474.        AI   R1,-256          Reset pointer
  475.  
  476. * Now read the block where the FDR will reside
  477.  
  478.        LDCR @B02,4           Select RAM bank 2
  479.        MOV  @SFDRAU,R7
  480.  
  481.        BL   @ALOT
  482.  
  483.        LI   R4,SECBUF
  484.        SRL  R8,1
  485.        JNC  OOU63
  486.        AI   R4,>100
  487. OOU63  SRL  R7,1
  488.        JNC  OOU64
  489.        AI   R8,>8000
  490. OOU64
  491.        BLWP @BANKIT
  492.        DATA SCSIRD
  493.        JEQ  OOU65
  494.        BL   @DSRERR
  495.        DATA >0600            Device Error
  496.  
  497. * Now copy our FDR to the SCSI buffer
  498. *
  499. OOU65
  500.        LI   R0,256
  501. OOU66  LDCR @B05,4
  502.        MOV  *R1+,R3
  503.        LDCR @ZERO,4
  504.        MOV  R3,*R4+
  505.        DECT R0
  506.        JNE  OOU66
  507.        AI   R1,-256
  508.  
  509.        BLWP @BANKIT          Write back out to disk
  510.        DATA SCSIWT
  511.        JEQ  OOU67
  512.        BL   @DSRERR
  513.        DATA >0600             Device Error
  514. OOU67
  515.  
  516.        LDCR @ZERO,4
  517.        B    @DSRRT            Hooray!  We're done
  518.